package com.itheima.controller;


import cn.itheima.health.entity.Result;
import cn.itheima.health.resources.MessageConstant;
import cn.itheima.health.service.SetmealService;
import com.itheima.pojo.Setmeal;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/setmeal")
public class SetmealController {

@Reference
private SetmealService setmealService;


    @RequestMapping("/findAll.do")
    public Result findAll(){
        try {
           List<Setmeal> list =  setmealService.findAll();
            return  new Result(true, MessageConstant.ADD_SETMEAL_SUCCESS,list);
        } catch (Exception e) {
            e.printStackTrace();
            return  new Result(false, MessageConstant.ADD_SETMEAL_FAIL);
        }

    }

    @RequestMapping("/findSetMealDetail.do")
    public Result findSetMealDetail(@RequestParam("id") Integer id){
        try {
           Setmeal setmeal=  setmealService.findSetMealDetail(id);
            return  new Result(true, MessageConstant.ADD_SETMEAL_SUCCESS,setmeal);
        } catch (Exception e) {
            e.printStackTrace();
            return  new Result(false, MessageConstant.ADD_SETMEAL_FAIL);
        }

    }
}
